<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="订单号">
                <el-input
                    v-model="queryParams.orderSn"
                    placeholder="请输入订单号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="订单ID">
                <el-input
                    v-model="queryParams.orderId"
                    placeholder="请输入订单ID"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="是否处理完毕">
                <el-select style="width: 200px;" v-model="queryParams.isHand"
                           clearable
                           placeholder="请选择">
                    <el-option
                        v-for="item in dict.type.is_hand_options"
                        :key="item.value"
                        :label="item.label"
                        :value="parseInt(item.value)"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="支付状态">
                    <el-select  style="width: 200px;" v-model="queryParams.payStatus"
                           clearable
                           placeholder="请选择">
                    <el-option
                        v-for="item in dict.type.pay_status_options"
                        :key="item.value"
                        :label="item.label"
                        :value="parseInt(item.value)"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="创建时间">
							<el-date-picker
							  v-model="dateRange"
							  type="datetimerange"
							  range-separator="-"
							  start-placeholder="开始日期"
							  value-format="yyyy-MM-dd HH:mm:ss"
							  style="width:333px;"
							  :default-time="['00:00:00','23:59:59']"
							  end-placeholder="结束日期">
							</el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="warning"
                    plain
                    icon="Download"
                    @click="handleExport"
                    v-hasPermi="['system:charge_return:export']"
                >导出
                </el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="ID" align="center" prop="id"/>
            <el-table-column label="订单号" align="center" prop="orderSn" :show-overflow-tooltip="true"/>
            <el-table-column label="订单ID" align="center" prop="orderId"/>
            <el-table-column label="充值金额" align="center" prop="rechargePrice" :formatter="(row) => {return '￥' + row.rechargePrice}"/>
            <el-table-column label="消费金额" align="center" prop="xfPrice" :formatter="(row) => {return '￥' + row.xfPrice}"/>
            <el-table-column label="退款金额" align="center" prop="tkPrice" :formatter="(row) => {return '￥' + row.tkPrice}"/>
            <el-table-column label="退款时间" align="center" prop="tkTime">
                <template slot-scope="{row}">
                    <span>{{ row.tkTime == '0' ? '-' : parseTime(row.tkTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="是否处理完毕" align="center" prop="isHand">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.is_hand_options" :value="row.isHand" />
                </template>
            </el-table-column>
            <el-table-column label="支付状态" align="center" prop="payStatus">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.pay_status_options" :value="row.payStatus" />
                </template>
            </el-table-column>
            <el-table-column label="昵称" align="center" prop="nickName"/>
            <el-table-column label="头像地址" align="center">
                <template slot-scope="{row}">
                  <el-image
                    v-if="row.avatar"
                    style="width: 40px; height: 40px"
                    :src="row.avatar"
                    :preview-src-list="[row.avatar]">
                  </el-image>
                </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center" prop="createTime">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
                <template slot-scope="{row}">
                    <el-button
                       type="text"
                       @click="handleUpdate(row, 1, 1)"
                       v-hasPermi="['system:charge_return:refund']"
                       v-if="row.isHand == '0'">确定退款
                    </el-button>
<!--                    <el-button link-->
<!--                               type="danger"-->
<!--                               @click="handleUpdate(row, 2)"-->
<!--                               v-hasPermi="['system:charge_return:remove']"-->
<!--                               v-if="row.refund_status == '0'">驳回提现-->
<!--                    </el-button>-->
                </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

    </div>
</template>

<script>
import * as api from "@/api/finance/charge_return";
export default {
  name: 'ChargeReturn',
  dicts: ['is_hand_options','pay_status_options',],
  components: {  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      list:[],//页面数据
      dateRange:[],
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      if(!this.dateRange) this.dateRange = []
      if(this.dateRange.length) {
        queryParams.startTime = this.dateRange[0]
        queryParams.endTime = this.dateRange[1]
      }
      api.listChargeReturn(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {// 查询参数
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryRef");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(api.EXPORT_URL, {
          ...this.queryParams
      }, `recharge_${new Date().getTime()}.xlsx`);
    },
    handleUpdate(row, refund_status) {
        var tips;
        if (refund_status == 1) {
            tips = '确定退款？';
        } else if (refund_status == -1) {
            tips = '驳回提现？';
        }
        this.$modal.confirm(tips).then( ()=> {
            return api.updateChargeReturn({id: row.id, type: refund_status});
        }).then(() => {
            this.getList();
            this.$modal.msgSuccess("操作成功");
        }).catch(() => {
        });
    },
  }
}
</script>
